<script src="<?php echo RESOURCE_URL?>/js/jquery.js"></script>
<div id="cont">
    <a href="javascript:void(0)"  id="add">添加</a>
<form id="search_form">
    <select name="search_field">
<?php foreach($fields as $k=>$v){?>
        <option value="<?php echo $k;?>"><?php echo $v;?></option>
        <?php }?>
    </select>
    <input type="text" name="field_value" value="<?php echo !empty($_POST['field_value'])?$_POST['field_value']:''?>" />
<input type="button" id="search_butn" value="查询" />
    </form>

<form action="index.php?act=user&op=del_more" method="post">
<table>
    <thead><tr><th><input type="submit" value="删除多个" onclick="javascript:return confirm('确定删除吗？')" /></th><th>编号</th><th>用户名</th><th>密码</th><th>角色</th><th>操作</th></tr></thead>
    <tbody>
<?php foreach($list as $v){?>
    <tr>
        <td><input type="checkbox" name="del[]" value="<?php echo $v['user_id']?>" /></td>
        <td><?php echo $v['user_id']?></td>
        <td><?php echo $v['user_name']?></td>
        <td><?php echo $v['user_password']?></td>
        <td><?php echo $v['user_role']?></td>
        <td><a href="javascript:void(0)" onclick="del_one(<?php echo $v['user_id']?>)">删除</a> | <a href="index.php?act=user&op=edit&user_id=<?php echo $v['user_id']?>">编辑</a></td>
    </tr>
<?php }?>
    </tbody>
    </table>
    </form>

<script>
    function del_one(id){
        if(!confirm('确定删除吗？')){
            return;
        }
        $.get('index.php?act=user&op=del',{user_id:id},function(res){
            if(res=='true'){
                alert('删除成功');
                window.location.href = "index.php?act=user&op=list";
            }else{
                alert('删除失败');
            }
        });
    }
    $(function(){

        $('#add').click(function(){
             window.location.href="index.php?act=user&op=add";
            /*$.get("index.php?act=user&op=add",function(res){
               // alert(res);return;
                $('#cont')[0].innerHTML = res;
            });*/
        });
        //查询事件$.post()
        $('#search_butn').click(function(){
            /* var arr = $('form[id=search_form]').serializeArray();
             $.post('index.php?act=user&op=list',{'search_field':arr[0].value,'field_value':arr[1].value},function(res){
             alert(res);
             $('#cont').html(res);
             });*/
            //查询事件$.ajax()
            var data_search = $('form#search_form').serialize();
            data_search+= '&search=1';
            // alert(data_search);return
            $.ajax({
                type: "post",

                url: "index.php?act=user&op=list",
                data: data_search,
                success: function(msg){
                    //alert(msg)
                    $('table tbody').html(msg);
                }
            });
        });
    })
</script>
</div>
